package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.mall.MallGoodsResourcesReadDao;
import com.party.core.dao.write.mall.MallGoodsResourcesWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallGoodsResources;
import com.party.core.service.mall.IMallGoodsResourcesService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * Created by huangwuming on 2018/3/27/027.
 */
@Service
public class MallGoodsResourcesService implements IMallGoodsResourcesService{
    @Autowired
    private MallGoodsResourcesWriteDao mallGoodsResourcesWriteDao;
    @Autowired
    private MallGoodsResourcesReadDao mallGoodsResourcesReadDao;

    /**
     * 新增
     * @param mallGoodsResources
     * @return
     */
    @Override
    public String insert(MallGoodsResources mallGoodsResources) {
        BaseModel.preInsert(mallGoodsResources);
        boolean result = mallGoodsResourcesWriteDao.insert(mallGoodsResources);
        if(result){
           return mallGoodsResources.getId();
        }
        return mallGoodsResources.getId() ;
    }

    /**
     *
     * @param mallGoodsResources
     * @return
     */
    @Override
    public boolean update(MallGoodsResources mallGoodsResources) {
        return mallGoodsResourcesWriteDao.update(mallGoodsResources);
    }

    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallGoodsResourcesWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallGoodsResourcesWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return mallGoodsResourcesWriteDao.batchDeleteLogic(ids);
        }
        return false;
    }

    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return mallGoodsResourcesWriteDao.batchDelete(ids);
    }

    @Override
    public MallGoodsResources get(String id) {
        return mallGoodsResourcesReadDao.get(id);
    }

    @Override
    public List<MallGoodsResources> listPage(MallGoodsResources mallGoodsResources, Page page) {
        return mallGoodsResourcesReadDao.listPage(mallGoodsResources,page);
    }

    @Override
    public List<MallGoodsResources> list(MallGoodsResources mallGoodsResources) {
        return mallGoodsResourcesReadDao.listPage(mallGoodsResources,null);
    }

    @Override
    public List<MallGoodsResources> batchList(@NotNull Set<String> ids, MallGoodsResources mallGoodsResources, Page page) {
        return null;
    }

    @Override
    public MallGoodsResources getUnique(MallGoodsResources mallGoodsResources) {
        return mallGoodsResourcesReadDao.getUnique(mallGoodsResources);
    }

    @Override
    public List<MallGoodsResources> findByGoodsId(String goodsId, int type) {
        MallGoodsResources resources = new MallGoodsResources();
        resources.setGoodsId(goodsId);
        resources.setType(type);
        return mallGoodsResourcesReadDao.listPage(resources, null);
    }

    @Override
    public void deleteByUnique(MallGoodsResources resources) {
        mallGoodsResourcesWriteDao.deleteByUnique(resources);
    }

    @Override
    public void deleteByGoodsId(String goodsId) {
        mallGoodsResourcesWriteDao.deleteByGoodsId(goodsId);
    }
}
